{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%reload_ext autoreload\n",
    "%autoreload 2\n",
    "%matplotlib inline\n",
    "import os\n",
    "os.environ[\"CUDA_DEVICE_ORDER\"]=\"PCI_BUS_ID\";\n",
    "os.environ[\"CUDA_VISIBLE_DEVICES\"]=\"0\"; "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "using Keras version: 2.2.4\n"
     ]
    }
   ],
   "source": [
    "import ktrain\n",
    "from ktrain import text"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Building an Arabic Sentiment Analyzer\n",
    "\n",
    "In this notebook, we will build a simple, fast, and accurate Arabic-language text classification model in 4 simple steps. More specifically, we will build a model that classifies Arabic hotel reviews as either positive or negative.\n",
    "\n",
    "The dataset can be downloaded from Ashraf Elnagar's GitHub repository (https://github.com/elnagara/HARD-Arabic-Dataset).\n",
    "\n",
    "Each entry in the dataset includes a review in Arabic and a rating between 1 and 5.  We will convert this to a binary classification dataset by assigning reviews with a rating of above 3 a positive label of 1 and assigning reviews with a rating of less than 3 a negative label of 0.\n",
    "\n",
    "(**Disclaimer:** I don't speak Arabic. Please forgive mistakes.) \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>text</th>\n",
       "      <th>neg</th>\n",
       "      <th>pos</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>“ممتاز”. النظافة والطاقم متعاون.</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>استثنائي. سهولة إنهاء المعاملة في الاستقبال. ل...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>استثنائي. انصح بأختيار الاسويت و بالاخص غرفه ر...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>“استغرب تقييم الفندق كخمس نجوم”. لا شي. يستحق ...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>جيد. المكان جميل وهاديء. كل شي جيد ونظيف بس كا...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                text  neg  pos\n",
       "0                  “ممتاز”. النظافة والطاقم متعاون.     1    0\n",
       "1  استثنائي. سهولة إنهاء المعاملة في الاستقبال. ل...    0    1\n",
       "2  استثنائي. انصح بأختيار الاسويت و بالاخص غرفه ر...    0    1\n",
       "3  “استغرب تقييم الفندق كخمس نجوم”. لا شي. يستحق ...    1    0\n",
       "4  جيد. المكان جميل وهاديء. كل شي جيد ونظيف بس كا...    0    1"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# convert ratings to a binary format:  1=positive, 0=negative\n",
    "import pandas as pd\n",
    "df = pd.read_csv('data/arabic_hotel_reviews/balanced-reviews.txt', delimiter='\\t', encoding='utf-16')\n",
    "df = df[['rating', 'review']] \n",
    "df['rating'] = df['rating'].apply(lambda x: 'neg' if x < 3 else 'pos')\n",
    "df.columns = ['label', 'text']\n",
    "df = pd.concat([df, df.label.astype('str').str.get_dummies()], axis=1, sort=False)\n",
    "df = df[['text', 'neg', 'pos']]\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## STEP 1:  Load and Preprocess the Data\n",
    "\n",
    "First, we use the `texts_from_df` function to load and preprocess the data in to arrays that can be directly fed into a neural network model. \n",
    "\n",
    "We set `val_pct` as 0.1, which will automatically sample 10% of the data for validation.  We specifiy `preprocess_mode='standard'` to employ normal text preprocessing.  If you are using the BERT model (i.e., 'bert'), you should use `preprocess_mode='bert'`.\n",
    "\n",
    "**Notice that there is nothing speical or extra we need to do here for non-English text.**  *ktrain* automatically detects the language and character encoding and prepares the data and configures the model appropriately.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "language: ar\n",
      "Word Counts: 151716\n",
      "Nrows: 95128\n",
      "95128 train sequences\n",
      "Average train sequence length: 23\n",
      "Adding 3-gram features\n",
      "max_features changed to 2689751 with addition of ngrams\n",
      "Average train sequence length with ngrams: 66\n",
      "x_train shape: (95128,75)\n",
      "y_train shape: (95128,2)\n",
      "10570 test sequences\n",
      "Average test sequence length: 22\n",
      "Average test sequence length with ngrams: 41\n",
      "x_test shape: (10570,75)\n",
      "y_test shape: (10570,2)\n"
     ]
    }
   ],
   "source": [
    "(x_train, y_train), (x_test, y_test), preproc = text.texts_from_df(df, \n",
    "                                                                   'text', # name of column containing review text\n",
    "                                                                   label_columns=['neg', 'pos'],\n",
    "                                                                   maxlen=75, \n",
    "                                                                   max_features=100000,\n",
    "                                                                   preprocess_mode='standard',\n",
    "                                                                   val_pct=0.1,\n",
    "                                                                   ngram_range=3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## STEP 2:  Create a Model and Wrap in Learner Object"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We will employ a neural implementation of the [NBSVM](https://www.aclweb.org/anthology/P12-2018/)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Is Multi-Label? False\n",
      "compiling word ID features...\n",
      "maxlen is 75\n",
      "building document-term matrix... this may take a few moments...\n",
      "rows: 1-10000\n",
      "rows: 10001-20000\n",
      "rows: 20001-30000\n",
      "rows: 30001-40000\n",
      "rows: 40001-50000\n",
      "rows: 50001-60000\n",
      "rows: 60001-70000\n",
      "rows: 70001-80000\n",
      "rows: 80001-90000\n",
      "rows: 90001-95128\n",
      "computing log-count ratios...\n",
      "done.\n"
     ]
    }
   ],
   "source": [
    "model = text.text_classifier('nbsvm', (x_train, y_train) , preproc=preproc)\n",
    "learner = ktrain.get_learner(model, \n",
    "                             train_data=(x_train, y_train), \n",
    "                             val_data=(x_test, y_test), \n",
    "                             batch_size=32)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## STEP 3: Estimate the LR\n",
    "We'll use the *ktrain* learning rate finder to find a good learning rate to use with *nbsvm*.  We will, then, select the highest learning rate associated with a still falling loss.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "simulating training for different learning rates... this may take a few moments...\n",
      "Epoch 1/1024\n",
      "48736/95128 [==============>...............] - ETA: 8s - loss: 0.5553 - acc: 0.7843\n",
      "\n",
      "done.\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEMCAYAAADJQLEhAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1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YkXg8GJgf9t+Vbl130zDUkkonJG5zEo+LiX8QvQBcbmZnJJYPTSxfT3zCnUdabad5COs3iI+x35bHPT5XwEIzG5BYdhTwUGL5ajN7toOsDyTdHwI8YGYDiX+4vtvOa44DxsTnUQGgp5kVu3vyN/iBQFU7rz8i6fe5B/hZ0vLTE/f/CvyijdfOB24xs/8FnnD3F81sLPCRu88CcPfNEG89ALeb2cHE39+KNrZ3AnBQUoupF/F/k3eBtcCgdn4HyUAqBJJKBvzE3X+3w8L4pCnHAUe4+1Yze474fMYAte7eeva1usTPGO3/Ddcl3bd21unIlqT7vwJudfdpiaw3tPOaCHC4u9d2sN1tbP/duoy7LzWzQ4gPiPYjM/sn8Fg7q18JrAHGEc/cVl4j3vKa2cZzBcR/D+km1EcgqTQT+KqZFQOY2WAz60/82+aGRBEYDRwe0P5fAr6Y6CsYQLyztzN6sX3M+fOTllcDJUmPnyI+mxYAiW/crS0C9mtnPy8TH9YY4sfgX0zcf5X4oR+Snt+BmQ0Ctrr7vcDPic+1uwQYaGYTE+uUJDq/exFvKTQB5xGfh7e1mcClZpabeG1FoiUB8RZEh2cXSWZRIZCUcfeniB/aeMXM5gMPE/8gfRLIMbNFxOemfTWgCI8QH054IXAv8CawqROvuwF4yMzeANYlLf87cEZzZzFwOTAh0bm6kDZmpnL3xcSnXCxp/RzxInKhmb1F/AP6isTybwHfTizfr53MY4HXzWwu8D/Aj9y9Hjib+HSm84CniX+b/zVwfmLZaHZs/TS7k/j79GbilNLfsb319WlgehuvkQylYaglqzQfs7f4XLKvA59099UpznAlUO3ud3Zy/UJgm7u7mU0h3nF8WqAhO87zAvEJ2zeElUG6lvoIJNs8YWa9iXf63pTqIpDwG+DM3Vj/UOKduwZsJH5GUSjMrIx4f4mKQDeiFoGISJZTH4GISJZTIRARyXIqBCIiWU6FQEQky6kQiIhkORUCEZEs9/8BACB1u6EnyHwAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "learner.lr_find(show_plot=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## STEP 4: Train the Model\n",
    "\n",
    "We will use the `autofit` method that employs a triangular learning rate policy and train 1 epoch.\n",
    "\n",
    "As shown in the cell below, our final validation accuracy is **94%** with only ~20 seconds of training over a single epoch!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "begin training using triangular learning rate policy with max lr of 0.005...\n",
      "Train on 95128 samples, validate on 10570 samples\n",
      "Epoch 1/1\n",
      "95128/95128 [==============================] - 21s 219us/step - loss: 0.2227 - acc: 0.9343 - val_loss: 0.1754 - val_acc: 0.9427\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<keras.callbacks.History at 0x7f58518c9320>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "learner.autofit(5e-3, 1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Inspecting Misclassifications"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "----------\n",
      "id:5338 | loss:13.94 | true:neg | pred:pos)\n",
      "\n",
      "“ممتاز جدا وأشكر كل العاملين في الفندق ع حسن ممتاز جدا وانصح به من جميع النواحي نظافه وتعامل راقي ومواصلات الي الحرم ه مدار الساعه وإفطار ممتاز وأشكر موظفو الاستقبال ع حسن اسقبالهم مكان مميز وسعر مميز فقطالماء للتعريف\n"
     ]
    }
   ],
   "source": [
    "learner.view_top_losses(n=1, preproc=preproc)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using Google Translate, the above roughly translates to:\n",
    "> *The hotel is very clean and the staff are very friendly and helpful.*\n",
    "\n",
    "This is clearly a positive review and was predicted as positive by our model.  The \"ground truth\" rating for this review is incorrect and explains the high loss. Perhaps the customer accidently entered a low rating."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Making Predictions on New Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "p = ktrain.get_predictor(learner.model, preproc)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Predicting label for the text\n",
    "> \"*The room was clean, the food excellent, and I loved the view from my room.*\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'pos'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p.predict(\"الغرفة كانت نظيفة ، الطعام ممتاز ، وأنا أحب المنظر من غرفتي.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Predicting label for:\n",
    "> \"*This hotel was too expensive and the staff is rude.*\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'neg'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p.predict('كان هذا الفندق باهظ الثمن والموظفين غير مهذبين.')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Save our Predictor for Later Deployment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "# save model for later use\n",
    "p.save('/tmp/arabic_predictor')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "# reload from disk\n",
    "p = ktrain.load_predictor('/tmp/arabic_predictor')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'pos'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# still works as expected after reloading from disk\n",
    "p.predict(\"الغرفة كانت نظيفة ، الطعام ممتاز ، وأنا أحب المنظر من غرفتي.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
